package com.fei.myback.entity;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.util.*;

/**
 * security登录实体类
 * <p>
 * isAccountNonExpired()：当前账号是否已经过期
 * isAccountNonLocked()：当前账号是否被锁
 * isCredentialsNonExpired()：当前账号证书（密码）是否过期
 * isEnabled()：当前账号是否被禁用
 */
@Component
@Data
@Slf4j
public class LoginUser implements UserDetails, Serializable {
    private static final long serialVersionUID = 7171722954972237961L;

    private String username;
    private String password;
    //权限集
    private List<? extends GrantedAuthority> authorities;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.authorities;
    }


    @Override
    public String getPassword() { // 最重点Ⅰ
        return this.password;
    }

    @Override
    public String getUsername() { // 最重点Ⅱ
        return this.username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
